package com.wangrui.controller;


import com.wangrui.utils.Page;
import com.wangrui.dto.StudentInfo;
import com.wangrui.pojo.Student;
import com.wangrui.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * <p>
 *  学生信息管理
 * </p>
 *
 * @author 王锐
 * @since 2020-07-10
 */
@Controller
@RequestMapping("/student")
public class StudentController {

    @Autowired
    private StudentService studentService;


    @RequestMapping("/studentList")
    public String studentListHtml()  {
        return "student/studentList";
    }
    @RequestMapping("/save")
    public String saveHtml()  {
        return "student/save";
    }
    @RequestMapping("/update")
    public String updateHtml()  {
        return "student/update";
    }

    @RequestMapping("/import")
    public String importHtml()  {
        return "student/import";
    }



    @RequestMapping("/queryAllStudents")
    public ResponseEntity<Map<String, Object>> queryAllStudents(
            @RequestParam("page")int page,
            @RequestParam("rows")int rows,
            @RequestParam("keyword")String keyword
    ) {
        Page<StudentInfo> page1 = new Page<>();
        page1.setPageSize(rows);
        page1.setPageIndex(page);
        page1.setKeyword(keyword);
        Map<String, Object> stringObjectMap = studentService.AllStudents(page1);
        return ResponseEntity.ok(stringObjectMap);
    }





    @RequestMapping("/studentSave")
    public ResponseEntity<Void> studentSave(Student student)  {

        studentService.studentSave(student);
        return new ResponseEntity<>(HttpStatus.CREATED);
    }

    @RequestMapping("/studentUpdate")
    public ResponseEntity<Void> studentUpdate(Student student)  {
        studentService.studentUpdate(student);
        return new ResponseEntity<>(HttpStatus.CREATED);
    }

    @RequestMapping("/studentDelete")
    @ResponseBody
    public String studentDelete(int  ids)  {
        studentService.studentDelete(ids);
        return "ok";
    }


}

